<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<%String path = request.getContextPath() ;%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>支付表巡检结果详情页面</title>
	<jsp:include page="../../import.jsp" flush="true" />
	<style type="text/css">
		.disp_title{
			position: relative;
		    clear: both;
		    width: 100%;
		    box-sizing: border-box;
		    padding: 6px;
		    text-align: left;
		    border-left: 1px solid #e9e9e9;
		    margin-bottom: -1px;
		    color: #00877a; 
		}
	</style>
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<form id="payRoute">
				<div class="fieldset1 tabel_col clearFix">
					<!-- 巡检结果 -->
					<div class="caption">
						<span class="title">支付表巡检结果</span>
					</div>
					<div class="fieldBox col_33">
						<div class="label">承租人名称</div>
						<div class="field">
							<span id="cstNm" name="cstNm">&nbsp;${detailInfo.cstNm }</span>
						</div>
					</div>
					<div class="fieldBox col_33">
						<div class="label">支付表号</div>
						<div class="field">
							<span id="paylistCode" name="paylistCode">&nbsp;${detailInfo.paylistCode }</span>
						</div>
					</div>
					<div class="fieldBox col_33">
						<div class="label">省公司档案袋编号</div>
						<div class="field">
							<span id="portfolioNumberProvince" name="portfolioNumberProvince">&nbsp;${detailInfo.portfolioNumberProvince }</span>
						</div>
					</div>
					<div class="fieldBox col_33">
						<div class="label">总部档案袋编号</div>
						<div class="field">
							<span id="portfolioNumber" name="portfolioNumber">&nbsp;${detailInfo.portfolioNumber }</span>
						</div>
					</div>
					<div class="fieldBox col_33">
						<div class="label">巡检状态</div>
						<div class="field">
							<span id="routeStateNm" name="routeStateNm">&nbsp;</span>
						</div>
					</div>
					<div class="fieldBox col_33">
						<div class="label">巡检结果</div>
						<div class="field">
							<span id="routeResultNm" name="routeResultNm">&nbsp;</span>
						</div>
					</div>
					<div class="fieldBox col_33">
						<div class="label">巡检时间</div>
						<div class="field">
							<span id="routeDate" name="routeDate">&nbsp;<fmt:formatDate type="date"  value="${detailInfo.mdfTm}"/></span>
						</div>
					</div>
					<div class="fieldBox col_33">
						<div class="label">巡检人</div>
						<div class="field">
							<span id="routePerson" name="routePerson">&nbsp;${detailInfo.routePerson }</span>
						</div>
					</div>
					<div class="fieldBox col_33">
						<div class="label"></div>
						<div class="field"></div>
					</div>
					<!-- 隐藏参数 -->
	                <div class="fieldBox col_100" style="display:none;">
						<div class="field">
							<input name="mainId" id="mainId" type="text" class="ui-textbox" value="${detailInfo.arcRouteMainId}">
							<input name="detailId" id="detailId" type="text" class="ui-textbox" value="${id}">
							<input name="btnFlag" id="btnFlag" type="text" class="ui-textbox" value="${btnFlag}">
	                        <input name="routeState" id="routeState" type="text" class="ui-textbox" value="${detailInfo.routeState}">
	                        <input name="routeResult" id="routeResult" type="text" class="ui-textbox" value="${detailInfo.routeResult}">
	                        <input name="contractNo" id="contractNo" type="text" class="ui-textbox" value='${contractNo}'>
	                        <input name="payListCode" id="payListCode" type="text" class="ui-textbox" value='${payListCode}'>
	                    </div>
	                </div>
	                
					<!-- 合同资料详情列表 -->
					<div class="disp_title">
						<span>
							合同资料、承租人资料、担保人资料
							<font color="black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${detailInfo.cstNm } &nbsp;&nbsp;${contractNo }</font>
						</span>
		            </div>
					<div class="fieldBox col_100">
						<div class="sqPanel">
							<div id="detailGrid">
								<div id="ligergrid_contract" class="sq-grid"></div>
							</div>
						</div>
					</div>
					
					<!-- 权证资料详情列表 -->
					<div class="disp_title">
						<span>权证资料</span>
		            </div>
					<div class="disp_title">
						<span><font color="black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${payListCode }</font></span>
		            </div>
					<div class="fieldBox col_100">
						<div class="sqPanel">
							<div id="detailGrid">
								<div id="ligergrid_warrant" class="sq-grid"></div>
							</div>
						</div>
					</div>
				</div>
				
				<!-- 表单按钮 -->
				<c:if test="${btnFlag == 'yes' }">
					<div class="btnsBox">
						<span id="saveBtn" class="sq-button sq-button-round" onclick="saveRouteSt()">保存</span>
						<span id="finishBtn" class="sq-button sq-button-round" onclick="finishRoute()">完成巡检</span>
		            </div>
	            </c:if>
			</form>
		</div>
	</div>
	
	<script type="text/javascript">
		var grid1 = null;
		var grid2 = null;
		//加载
		$(function () {
			initForm();//初始化表单
		    initContractGrid();//初始化合同资料
		    initWarrantGrid();//初始化权证资料
		    setData();//初始化表头数据
		});
		
		//初始化表单
		function initForm(){
			$("#payRoute").ligerForm({
				validate: true
			});
		}
		
		//查询参数
		function getSearchParams(){
			var form = new liger.get("payRoute");
			var data = form.getData();
			return data;
		}
		
		//设置页面数据
	    function setData(){
			//日期判空
 	    	//巡检状态
 	    	if("${detailInfo.routeState}"){
 	    		if("${detailInfo.routeState}" == "0"){
 	 	    		$("#routeStateNm").html("未巡检");
 	 	    	}else if("${detailInfo.routeState}" == "1"){
 	 	    		$("#routeStateNm").html("巡检中");
 	 	    	}else if("${detailInfo.routeState}" == "2"){
 	 	    		$("#routeStateNm").html("巡检结束");
 	 	    	}
 	    	}
 	    	//巡检结果
 	    	if("${detailInfo.routeResult}"){
 	    		if("${detailInfo.routeResult}" == "0"){
 	 	    		$("#routeResultNm").html("缺失");
 	 	    	}else if("${detailInfo.routeResult}" == "1"){
 	 	    		$("#routeResultNm").html("齐全");
 	 	    	}
 	    	}
	    }
		
		//格式化时间1：YYYY-MM-DD
		function renderDate(dateStr1){
			var dateStr2 = "";
			if(null != dateStr1){
				var date = new Date(dateStr1);
				dateStr2 = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
			}
			return dateStr2;
		}
		
		//初始化合同资料列表
		function initContractGrid(){
			var contractNo = $("#contractNo").val();
			$("#ligergrid_contract").ligerGrid({
				url:'<%=path%>/archive/arcRouteDetail/initGridList.do',
				method:'get',
				parms:{contractNo: contractNo, arcLevel: "1"},
				columns:[
					{ display: '权证类别', name: 'fileFlagNm', minWidth: 150, align: 'center', enabledSort: true},
					{ display: '权证名称', name: 'fileName', minWidth: 180, align: 'center', enabledSort: true},
					{ display: '资料类型', name: 'dossierTempNm', minWidth: 160, align: 'center', enabledSort: true},
					{ display: '是否必须', name: 'ischoiceNm', width: 90, align: 'center', enabledSort: true},
					{ display: '存档份数', name: 'dossierCountT', minWidth: 160, align: 'center', enabledSort: true},
					getCheckedArcNumColumn(),
					{ display: '档案管理明细表ID', name: 'id', hide: true, align: 'center', width: 5 }
				],
				//pageSize:10,
				root:'rows',
				record:'total',
				usePager: false,//是否有分页便签
				hideLoadButton:false,
				width:'100%',
				heightDiff:-2,
				enabledEdit: true,
				checkbox:false,//列表是否有选择框
				rownumbers:true//列表是否有行号
			});
			grid1 = liger.get("ligergrid_contract");
		}
		
		//初始化权证资料列表
		function initWarrantGrid(){
			var contractNo = $("#contractNo").val();
			var payListCode = $("#payListCode").val();
			$("#ligergrid_warrant").ligerGrid({
				url:'<%=path%>/archive/arcTransferMain/initGridList.do',
				method:'get',
				parms:{contractNo: contractNo, payListCode: payListCode, arcLevel: "2",fileFlag:"3"},
				columns:[
					{ display: '权证类别', name: 'fileFlagNm', minWidth: 150, align: 'center', enabledSort: true},
					{ display: '权证名称', name: 'fileName', minWidth: 180, align: 'center', enabledSort: true},
					{ display: '资料类型', name: 'dossierTempNm', minWidth: 160, align: 'center', enabledSort: true},
					{ display: '是否必须', name: 'ischoiceNm', width: 90, align: 'center', enabledSort: true},
					{ display: '存档份数', name: 'dossierCountT', minWidth: 160, align: 'center', enabledSort: true},
					getCheckedArcNumColumn(),
					{ display: '档案管理明细表ID', name: 'id', hide: true, align: 'center', width: 5 }
				],
				//pageSize:10,
				usePager: false,//是否有分页便签
				root:'rows',
				record:'total',
				hideLoadButton:false,
				width:'100%',
				heightDiff:-2,
				enabledEdit: true,
				checkbox:false,//列表是否有选择框
				rownumbers:true//列表是否有行号
			});
			grid2 = liger.get("ligergrid_warrant");
		}
		
		//"核实存档份数"列是否可编辑
	    function getCheckedArcNumColumn(){
			var data = {display: '核实存档份数', name: 'checkedArcNum', width: 150, align: 'center', enabledSort: true};
			<c:if test="${btnFlag == 'yes' }">
				data = {display: '核实存档份数', name: 'checkedArcNum', width: 150, type: 'int', 
							editor: {
								type: 'int'
							}
				};
			</c:if>
			return data;
		}
		
		//保存巡检状态
		function saveRouteSt(){
            var detailId = $("#detailId").val();
            var btnFlag = $("#btnFlag").val();
            if(null == detailId){
            	top.$.ligerDialog.SQalert({content: "巡检明细表ID为空,不能保存巡检状态！",SQ_type: "warning"});
				return false;
            }
            
            var ligerForm = liger.get("payRoute");
            var data=ligerForm.getData();
            data['id']=detailId;
            data['routeState']='1';
            data['griddata1']=JSON.stringify(grid1.getData());
            data['griddata2']=JSON.stringify(grid2.getData());
         
            $.ligerDialog.confirm('确定保存巡检明细状态吗?', function (flag) {
				if(flag == false)return;
				var wait_dialog = null;
				$.ajax({
					url: '<%=path%>/archive/arcRouteDetail/modify.do?',
					type: 'post',
					dataType: 'json',
					data: data,
					beforeSend: function(){
						wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
					},
					success:function(msg){
						wait_dialog.close();
						if(msg.success == 1){
							top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
							//刷新当前页面
							window.location.href="<%=path%>/archive/arcRouteDetail/toPayDetailPage.do?id="+detailId+"&btnFlag="+btnFlag;
							//执行前置页面的回调函数
							var callback = GET_W2Wcallback ();
							if(callback){
								callback();
							}
						}else{
							top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
						}
					}
				});
			});
        }
		
		//完成巡检
		function finishRoute(){
            var detailId = $("#detailId").val();
            if(null == detailId){
            	top.$.ligerDialog.SQalert({content: "巡检明细表ID为空,不能保存巡检明细信息！",SQ_type: "warning"});
				return false;
            }
            var jsondata = '{detailId:'+detailId+',griddata1:'+JSON.stringify(grid1.getData())+',griddata2:'+JSON.stringify(grid2.getData())+'}';
            console.log(jsondata);
            $.ligerDialog.confirm('确定完成巡检吗?', function (flag) {
				if(flag == false)return;
				var wait_dialog = null;
				var url = '<%=path%>/archive/arcRouteDetail/finishRoute.do';
				$.ajax({
					type: 'post',
					url: url,
					contentType: 'application/json',
					dataType: 'json',
					data: JSON.stringify(jsondata),
					beforeSend: function(){
						wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
					},
					success:function(msg){
						wait_dialog.close();
						if(msg.success == 1){
							top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
							Remove_navTab();//关闭当前页签
						}else{
							top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
						}
					}
				});
			});
        }
	</script>
</body>
</html>